﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.Text;

namespace ParseXAML
{
    class Utils
    {
        public static string ReplaceParams(string str, params object[] values)
        {
            for (int i = 0; i < values.Length; i++)
                str = str.Replace("{" + i.ToString() + "}", values[i].ToString());
            return str;
        }

        public static int GetNumerOfDigit(string str)
        {
            int o = 0;
            for (int i = 0; i < str.Length; i++)
                if (Char.IsDigit(str, i))
                    o++;
            return o;
        }

        public static XmlAttribute GetName(XmlElement node)
        {
            // get Name element (sometimes qualified, sometimes not ;) 
            XmlAttribute xamlElementName = node.GetAttributeNode("Name");
            if (xamlElementName == null)
            {
                xamlElementName = node.GetAttributeNode("Name", NamespaceAssociations.nsXamlName);
            }
            return xamlElementName;
        }

        internal static string ReplaceNamedParams(string value, Dictionary<string, string> values)
        {
            foreach (var p in values)
            {
                value = value.Replace("%" + p.Key + "%", p.Value);
            }
            return value;
        }

    }
}
